<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2022/5/26.
 */

namespace Zane\View\Compiler\Concerns;

trait compileField
{
    protected function compileField($expression): string
    {
        $expression = mb_strcut($expression, 1, mb_strlen($expression) - 2);
        if (!preg_match('/^[\"|\']+.*$/x', $expression)) {
            $expression = "'{$expression}'";
        }

        return "<?php echo e(\$field[{$expression}]); ?>";
    }
}
